<?php
	$name 			= $this->formText('name',$this->Item['name'],array('class'=>'txtmedium'));
	$alias 			= $this->formText('alias',$this->Item['alias'],array('class'=>'txtmedium'));
	$url 			= '<div class="link_url">' . $this->formText('url',$this->Item['url'],array('class'=>'txtmedium')) . '</div>';
	$picture 		= $this->formFile('picture',array('style'=>'width: 250px'));
	$start 			= $this->formText('start',$this->Item['start'],array('class'=>'txtmedium','id'=>'start'));
	$end 			= $this->formText('end',$this->Item['end'],array('class'=>'txtmedium','id'=>'end'));
	
	$position 		= $this->formSelect('position',$this->Item['position'],array(''),$this->tblPositions);
	$summary 		= $this->formTextarea('summary',$this->Item['summary'],array('rows'=>'10'));
	$content		= $this->cmsReplaceString($this->Item['content']);
	$content		= '<div class="con_advert">' . $this->cmsEditor('content',$content,array('toolbar'=>'Default','language'=>'vi')) . '</div>';
	
	
	$options 		= array($this->translate('Inactive'),$this->translate('Active'));
	$status 		= $this->formRadio('status',$this->Item['status'],null,$options, ' ');
	
	$options 		= array($this->translate('Image'),$this->translate('Flash'));
	$val			= $this->Item['type'];
	if(empty($val))$val = 0 ;
	$type 			= $this->formRadio('type',$val,null,$options, ' ');
	
	$options 		= array($this->translate('No'),$this->translate('Yes'));
	$special 		= $this->formRadio('special',$this->Item['special'],null,$options, ' ');
	
	$order 			= $this->formText('order',$this->Item['order'],array('class'=>'txtshort cont_add'));
	$form_add		= "<div class='select_advert'><span id='add_url' class='add_url'>Add url</span><span id='add_text' class='add_text'>Add Text</span></div>";
	
	/*...........Picture............*/
	$imgArr 		= !empty($this->Item['picture'])?array( FILES_URL . '/products/images100x100/'.$this->Item['picture']):'';
	$image 	= $this->cmsUserAvatar($inputInfo, $imgArr);
	if(!empty($this->Item['picture'])){
		if($this->Item['type'] == 0){
			$urlimage   = FILES_URL . '/adverts/images100x100/'. $this->Item['picture'];
		  	$imgimage  = '<span><img src="' . $urlimage . '" width="" height="40"></span>'; 
		  	$picture  = $imgimage ."<br/>" . $this->formFile('picture',array('style'=>'margin-left:173px'));
		}else{
			$imgimage  = '<p style="color:red">' . $this->Item['picture'] . '</p>'; 
		  	$picture  = $imgimage . $this->formFile('picture',array('style'=>'margin-left:173px'));
		}	  	
	}else{
		$picture  = $this->formFile('picture',array('style'=>'margin-left:5px'));
	}
 	$current_stadium = $this->formHidden('current_stadium_picture',$this->Item['picture']);  
	
	$Input1 = array(
					array('Label'=>$this->translate('Title'),'input'=>$name,'info'=>0),
					array('Label'=>$this->translate('Alias'),'input'=>$alias,'info'=>0),
					array('Label'=>$this->translate('Type'),'input'=>$type,'info'=>0),
					array('Label'=>$this->translate('Picture') . ' / Flash','input'=>$picture,'info'=>0),
					array('Label'=>$this->translate('Start'),'input'=>$start,'info'=>0),
					array('Label'=>$this->translate('End'),'input'=>$end,'info'=>0),
					array('Label'=>$this->translate('Special'),'input'=>$special,'info'=>0),
					array('Label'=>$this->translate('Position'),'input'=>$position,'info'=>0),
					);
	$Input2 = array(
					array('Label'=>$this->translate('Status'),'input'=>$status,'info'=>0),
					array('Label'=>$this->translate('Summary'),'input'=>$summary,'info'=>0),
					array('Label'=>$this->translate('Order'),'input'=>$order,'info'=>0),
					);
	if(count($this->errors)>0){
		$errors = $this->formErrors($this->errors,array('id'=>'errors'));
	}
?>
<form name="appForm" method="post" action="" enctype="multipart/form-data">

                        <?php echo $this->render('toolbar.php')?>
                        <div class="clr"></div>
                        <?php echo $this->render('sublink.php')?>
                        <?php echo $errors;?>

                        <!-- BEGIN: CONTENT -->
                        <div id="element-box">
                            <div class="t">
                                <div class="t">
                                    <div class="t"></div>
                                </div>
                            </div>
                            <div class="m">
                                <!-- BEGIN: ELEMENT BOX -->
						<div id="adminfieldset">
                             <div class="adminheader">Detail</div>								
								<?php echo $this->partialLoop('rows.php',$Input1) . $current_stadium ;?>
								<div id="tets-ajax"></div>
								<?php echo $this->partialLoop('rows.php',$Input2) . $current_stadium . $form_add . $url .$content ;?>                         
							</div>
							
                                <!-- END: ELEMENT BOX -->	
                              <div class="clr"></div>
                            </div>
                            <div class="b">
                                <div class="b">
                                    <div class="b"></div>
                                </div>
                            </div>
                        </div>
                        <!-- END: 	CONTENT -->
                    </form>
                    
<script type="text/javascript">
$(document).ready(function(){
	$(function() {
	   var today = new Date();
	   var year = today.getFullYear();
	   var maxYear = today.getFullYear()+10;
	   $("#start").datepick({
	    minDate: new Date(year, 1 - 1, 25),
	    maxDate: new Date(maxYear, 12 - 1, 31),
	    yearRange: "+10:-70",
	       dateFormat: 'yyyy-mm-dd',
	    showOn: "both"
	   });
	  });  
	 });
$(document).ready(function(){
	$(function() {
		//load link url
		$("#add_url").click(function(){
			$(this).parent().next().next(".con_advert").hide(500);
			$(this).parent().next(".link_url").slideToggle();
		});
		//load link content advert
		$("#add_text").click(function(){
			$(this).parent().next(".link_url").hide(500);
			$(this).parent().next().next(".con_advert").slideToggle();
		});
		//load ajax form 
		$('#position').change(function(){
			var poi = $("#position").val();
			$.ajax({
		          type: "POST",
		              url: '<?php echo $this->url(array('module'=>'news','controller'=>'admin-advert','action'=>'load-positions'));?>',
		              data: "position_id=" + poi,
		              success: function (data){
		         		$("#tets-ajax").html(data);
		              }
		       });
		});
		$.ajax({
	          type: "POST",
	              url: '<?php echo $this->url(array('module'=>'news','controller'=>'admin-advert','action'=>'load-positions'));?>',
	              data: "position_id=" + '<?php echo $this->Item['position'];?>',
	              success: function (data){
	         		$("#tets-ajax").html(data);
	              }
	       });
	   //jquery datepicker	
	   var today = new Date();
	   var year = today.getFullYear();
	   var maxYear = today.getFullYear()+10;
	   $("#end").datepick({
	    minDate: new Date(year, 1 - 1, 25),
	    maxDate: new Date(maxYear, 12 - 1, 31),
	    yearRange: "+10:-70",
	       dateFormat: 'yyyy-mm-dd',
	    showOn: "both"
	   });
	  });  
	 });
	 
</script>
